package com.hontech.bvapp2.store

import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import com.hontech.bvapp2.app.AppContext
import com.hontech.bvapp2.utils.externStorePath
import com.hontech.bvapp2.utils.runIO

private val DB_PATH = externStorePath("data.db")
private const val VERSION = 1

object Store : SQLiteOpenHelper(AppContext, DB_PATH, null, VERSION) {

    var upgradeFlag = false
        private set

    private val db = writableDatabase

    suspend fun<T> run(cb: (db: SQLiteDatabase) -> T): T {
        return runIO { cb(db) }
    }

    override fun onCreate(db: SQLiteDatabase?) {
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        upgradeFlag = true
    }
}



